Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

392
Views
how to manage [object HTMLDivElement] and get its content?

I have saved an array in local storage and trying to use it but when I console.log the localstorage.getitem it returns
[object HTMLDivElement] I have tried to use .innerhtml or [...] on it but they didn't work. Btw, since it's an array, I have to use JSON.stringify(movieWatchlistArray):

 localStorage.setItem("key",JSON.stringify(movieWatchlistArray))
 let str =localStorage.getItem("key")
 console.log(JSON.parse(str) )

But when I do this, it will return an empty object inside an array while when I console.log the original array it's fine so I tried to do it without JSON part, it worked but returns a string of
[object HTMLDivElement]

 localStorage.setItem("key",movieWatchlistArray)  
 let str =localStorage.getItem("key")
 console.log(str)

So how to get the content of [object HTMLDivElement] I have used .innerhtml but it says can't use .innerHTML on undefined .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

when you trying to save an element in localstorage you should save the .outerHTML of it, not the element itself. although it's not recommended to save the whole HTML in local storage instead save the data as an object and use it in js to render the HTML. so in this case it will be :

movieWatchlistArray.unshift(document.querySelector(`.movie--${moviePageNumber-1}`).outerHTML) 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!